<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //思路:最后一轮后面的不用买票，直接一个for循环加起来
    function timeRequiredToBuy(tickets, k) {
      let s = 0
      for (let i = 0; i < tickets.length; i++)
        s += Math.min(tickets[i], i <= k ? tickets[k] : tickets[k] - 1)
      return s
    };
    console.log(timeRequiredToBuy(tickets = [2, 3, 2], k = 2))
  </script>
</body>

</html>